package com.health.mapp.utils;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;

import redis.clients.jedis.JedisPoolConfig;
import redis.clients.jedis.JedisShardInfo;
import redis.clients.jedis.ShardedJedisPool;
import net.rubyeye.xmemcached.MemcachedClient;

import com.health.mapp.utils.MappGlobal;
 

public class MappGlobal {

	private boolean debug = false;

	private boolean useDB = false;

	private boolean hasBoss = false;

	private String webRootPath = "";

	private MemcachedClient memcachedClient;
	
	private String softDetailUrl;
	
	private String detailPrefixUrl;
	
	//private HashMap<Integer, AreaInfo> areaInfoMap = new HashMap<Integer, AreaInfo> ();
	
//	private HashMap<String, HashMap<String, String>> sysConfigMap = new HashMap<String, HashMap<String, String>>();
	
	private HashMap<String, String> propertiesConfig = new HashMap<String, String>();

	private static ShardedJedisPool jedisPool = null;
	
//	public HashMap<Integer, AreaInfo> getAreaInfoMap() {
//		if (areaInfoMap.isEmpty()) {
//			AreaInfoDao dao = new AreaInfoDao();
//			List<AreaInfo> list = dao.selectAll();
//			for (AreaInfo a : list) {
//				areaInfoMap.put(a.getAreaid(), a);
//			}
//		}
//		return areaInfoMap;
//	}
//
//	public void setAreaInfoMap(HashMap<Integer, AreaInfo> areaInfoMap) {
//		this.areaInfoMap = areaInfoMap;
//	}

//	public HashMap<String, HashMap<String, String>> getSysConfigMap() {
//		return sysConfigMap;
//	}
//
//	public void setSysConfigMap(HashMap<String, HashMap<String, String>> sysConfigMap) {
//		this.sysConfigMap = sysConfigMap;
//	}

	public HashMap<String, String> getPropertiesConfig() {
		return propertiesConfig;
	}

	public void setPropertiesConfig(HashMap<String, String> propertiesConfig) {
		this.propertiesConfig = propertiesConfig;
	}
	
	public String getDetailPrefixUrl() {
		return detailPrefixUrl;
	}

	public void setDetailPrefixUrl(String detailPrefixUrl) {
		this.detailPrefixUrl = detailPrefixUrl;
	}

	public String getSoftDetailUrl() {
		return softDetailUrl;
	}

	public void setSoftDetailUrl(String softDetailUrl) {
		this.softDetailUrl = softDetailUrl;
	}

	public MemcachedClient getMemcachedClient() {
		return memcachedClient;
	}

	public void setMemcachedClient(MemcachedClient memcachedClient) {
		this.memcachedClient = memcachedClient;
	}

	public String getWebRootPath() {
		return webRootPath;
	}

	public void setWebRootPath(String webRootPath) {
		this.webRootPath = webRootPath;
	}

	public boolean isUseDB() {
		return useDB;
	}

	public boolean isHasBoss() {
		return hasBoss;
	}

	public void setHasBoss(boolean hasBoss) {
		this.hasBoss = hasBoss;
	}

	public void setUseDB(boolean useDB) {
		this.useDB = useDB;
	}

	public boolean isDebug() {
		return debug;
	}

	public void setDebug(boolean debug) {
		this.debug = debug;
	}

	private static MappGlobal globalInstance;

	private MappGlobal() {

	}

	public static MappGlobal getInstance() {
		if (null == globalInstance) {
			globalInstance = new MappGlobal();
		}
		return globalInstance;
	}

	synchronized public static ShardedJedisPool getPoolInstance() {
		try {
			if (null == jedisPool) {
				HashMap<String, String> config = MappGlobal.getInstance().getPropertiesConfig();
				String serverAddress = config.get("redis.serverAddress");
				int servicePort = Integer.valueOf(config.get("redis.servicePort"));
				
				List<JedisShardInfo> shards = Arrays.asList(new JedisShardInfo(serverAddress, servicePort));
				jedisPool = new ShardedJedisPool(new JedisPoolConfig(), shards);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		return jedisPool;
	}
}
